<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
 <%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" +request.getServerPort() + path + "/";
%>   
   <jsp:include page="head.jsp"></jsp:include>
   <c:if test="${SmallClassify==null}">
    <c:redirect url="../showProduct_Servlet?manage=addproduct"></c:redirect>
   </c:if>
	<div class="main">
		<h2>添加商品</h2>
		<div class="manage">
			<form id="productAdd"  enctype="multipart/form-data" action="<%=basePath%>ChangeAddDeleteProduct_Servlet?manage=add"  method="post" accept-charset="utf-8">
				<table class="form">
					<tr>
						<td class="field">商品名称(*)：</td>
						<td><input type="text" class="text" name="productName" /><span class="c1"></span></td>
					</tr>
                    <tr>
						<td class="field">描述：</td>
						<td><input type="text" class="text" name="productDetail" /></td>
					</tr>
					<tr>
						<td class="field">所属分类：</td>
						<td>
							<select name="parentId">
							<c:forEach items="${SmallClassify}" var="obj" >
							   <option value="${obj.small_id}">${obj.small_name}---${obj.big_name}</option>
							</c:forEach>
							</select>
						</td>
					</tr>					
					<tr>
						<td class="field">商品价格(*)：</td>
						<td><input type="text" class="text tiny" name="productPrice" /> 元<span class="c2"></span></td>
					</tr>					
					<tr>
						<td class="field">库存(*)：</td>
						<td><input type="text" class="text tiny" name="productNumber"  id="productNumber"/><span class="c3"></span></td>
					</tr>
					<tr>
						<td class="field">商品图片(*)：</td>
						<td><input type="file" class="text" id="photo" name="photo" onchange="document.getElementById('photo').value=this.value"/><span class="c4"></span></td>
					</tr>
					<!-- 通过input-file获得的是文件名，不是文件路径 -->				
					<tr>
						<td></td>
						<td><label class="ui-blue"><input type="submit" name="submit" value="确定" /></label></td>
					</tr>
				</table>
			</form>
		</div>
	</div> 
	<div class="clear"></div>
</div>
<div id="img"></div>
<div id="fot" style="text-align:center;margin:auto">
	Copyright &copy; 2013 云和学院 All Rights Reserved. 京ICP证1000001号</div>
	
</body>
</html>
<script type="text/javascript">
$(function(){
	var reg=new RegExp(/^\d{1,}$/);
	//非空验证
	$("[name='productName']").blur(function(){
		if($(this).val()==""){
			$(".c1").html("商品名称不能为空啊");				
		}
	});
	$("[name='productPrice']").blur(function(){
		if($(this).val()==""){
			$(".c2").html("商品价格不能为空啊");				
		}
		if($(this).val()!=""&&reg.test($(this).val())==false){
			$(".c2").html("请输入数字");
		}
	});
	$("[name='productNumber']").blur(function(){
		if($(this).val()==""){
			$(".c3").html("商品库存不能为空啊");				
		}
		if($(this).val()!=""&&reg.test($(this).val())==false){
			$(".c3").html("请输入数字");
		}

	});
	$("[name='photo']").blur(function(){
		if($(this).val()==""){
			$(".c4").html("商品图片不能为空啊");				
		}
	});
	
	$("[name='productName']").focus(function(){
			$(".c1").html("");				
	});
	$("[name='productPrice']").focus(function(){
			$(".c2").html("");				
	});
	$("[name='productNumber']").focus(function(){
			$(".c3").html("");				
	});
	$("[name='photo']").focus(function(){
			$(".c4").html("");				
	});
	

});


</script>